package com.pattern.strategy.typesource;

import com.pattern.strategy.promotion.*;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * Created by wangzhengpeng
 */
public class TypeStrategyFactory {

    private static Map<String, IPromotionStrategy> PROMOTIONS = new HashMap<String, IPromotionStrategy>();

    static {
        PROMOTIONS.put(TypeKey.type1 + SourceKey.source1, new CouponStrategy());
        PROMOTIONS.put(TypeKey.type2 + SourceKey.source2, new CashbackStrategy());
        PROMOTIONS.put(TypeKey.type3 + SourceKey.source3, new GroupbuyStrategy());
    }

    private static final IPromotionStrategy EMPTY = new EmptyStrategy();

    private TypeStrategyFactory() {
    }

    public static IPromotionStrategy getPromotionStrategy(String promotionKey) {
        IPromotionStrategy strategy = PROMOTIONS.get(promotionKey);
        return strategy == null ? EMPTY : strategy;
    }

    private interface TypeKey {
        String type1 = "type1";
        String type2 = "type2";
        String type3 = "type3";
    }

    private interface SourceKey {
        String source1 = "source1";
        String source2 = "source2";
        String source3 = "source3";
    }

    public static Set<String> getPromotionKeys() {
        return PROMOTIONS.keySet();
    }
}
